<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>

<head>
    <base href="<%=basePath%>"/>
    <title>襄阳蓝芯智能化办公系统</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" href="view/bootstrap-3.3.5/css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="view/bootstrapvalidator/css/bootstrapValidator.css" />
    <script charset="utf-8" src="view/jquery/jquery-1.10.2.min.js"></script>
    <script charset="utf-8" src="view/bootstrap-3.3.5/js/bootstrap.js"></script>
    <script charset="utf-8" src="view/bootstrapvalidator/js/bootstrapValidator.js"></script>
</head>
<body>

<form action="qx/insertFunction" id="editRoleFunForm" method="post">
    <input type="hidden" name="oid" value="${selectRoleUser.oid}">
    <input type="hidden" name="fids" id="fids">
</form>

<div class="panel panel-primary">

    <div class="panel-heading">
        <h4 class="panel-title">编辑 [ ${selectRoleUser.roleName} ] 角色下权限</h4>
    </div>

    <div class="panel-body">
        <form action="" id="myform" method="post" class="form-horizontal"
              role="form">

            <c:forEach items="${functions}" var="fun">
                <div class="col-md-4">
                    <div class="col-md-5 form-group">
                        <label>
                            <input type="checkbox" id="f${fun.oid}" onclick="checkALL(${fun.oid})"
                                   value="${fun.oid}"
                            <c:forEach items="${selectRoleUser.functions}" var="rolefc">
                                   <c:if test="${rolefc.oid==fun.oid}">checked</c:if>
                            </c:forEach>
                            >${fun.functionName}
                        </label>
                    </div>

                    <c:forEach items="${fun.functions}" var="ction">
                        <div class="col-md-11 col-md-offset-1">
                            <label>
                                <input type="checkbox" name="cf${fun.oid}" onclick="checkChild(${fun.oid})"
                                       value="${ction.oid}"
                                <c:forEach items="${selectRoleUser.functions}" var="rolefc">
                                       <c:if test="${ction.oid==rolefc.oid}">checked</c:if>
                                </c:forEach>
                                >${ction.functionName}
                            </label>
                        </div>
                    </c:forEach>
                </div>
            </c:forEach>

            <div class="form-group col-md-12">
                <div class="col-md-10  col-md-offset-2">
                    <a type="button" href="javascript:history.back()"
                       class="btn btn-info">返回</a>
                    <button type="button" id="editRoleFunBtn" class="btn btn-success">提交信息</button>
                </div>
            </div>

        </form>
    </div>
</div>

</body>
<script type="text/javascript">
    function checkALL(oid) {
        $("input[name='cf" + oid + "']").prop("checked", $("#f" + oid).prop('checked'));
    }

    function checkChild(oid) {
        if ($("input[name='cf" + oid + "']:checked").length == $("input[name='cf" + oid + "']").length) {
            $("#f" + oid).prop('checked', "checked");
        } else {
            $("#f" + oid).prop('checked', "");
        }
    }

    $(document).ready(function () {
        $("#editRoleFunBtn").click(function () {
            var count = $("input[type='checkbox']:checked").length;
            var fids = "";
            for (var i = 0; i < count; i++) {
                fids = fids + $("input[type='checkbox']:checked")[i].value + ",";
            }
            fids = fids.slice(0, -1);

            $("#fids").val(fids);
            $("#editRoleFunForm").submit();
        });
    })
</script>
</html>
